<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="增加支付配置">
    </el-page-header>
    <div class="model-content">
      <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="支付标识" prop="key">
              <el-input v-model="form.key" name="key">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="支付名称" prop="name">
              <el-input v-model="form.name" name="name">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="支付模式" prop="payType">
              <nb-select catalog="payType" v-model="form.payType"></nb-select>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="服务商Id" prop="platformId">
              <el-input v-model="form.platformId" name="platformId">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="服务商户号" prop="platformMchId">
              <el-input v-model="form.platformMchId" name="platformMchId">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="appId" prop="appId">
              <el-input v-model="form.appId" name="appId">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="商户号" prop="mchId">
              <el-input v-model="form.mchId" name="mchId">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="商户Key" prop="mchKey">
              <el-input v-model="form.mchKey" name="mchKey">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="证书路径" prop="keyPath">
              <el-input v-model="form.keyPath" name="keyPath">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="通知Url" prop="notifyUrl">
              <el-input v-model="form.notifyUrl" name="notifyUrl">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="费率" prop="rate">
              <el-input v-model="form.rate" name="rate">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="note">
              <el-input v-model="form.note" name="note" type="textarea"></el-input>
            </el-form-item>

          </el-col>

          <el-col :span="22">
            <el-form-item>
              <el-button @click="goBack">取消</el-button>
              <el-button type="primary" @click="add">确定</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import common from "@/mixins/common.js";
import {ElLoading} from "element-plus";

import nbSelect from "@/components/nbSelect.vue";

export default {
  name: "PayConfig_add",
  mixins: [common],
  components: {nbSelect},
  data() {
    return {
      form: {
        key: '',
        name: '',
        payType: '',
        platformId: '',
        platformMchId: '',
        appId: '',
        mchId: '',
        mchKey: '',
        keyPath: '',
        notifyUrl: '',
        rate: '',
        note: ''
      },
      rules: {
        key: [
          {required: true, message: '请输入支付标识', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '请输入支付名称', trigger: 'blur'}
        ],
        platformId: [
          {required: true, message: '请输入服务商Id', trigger: 'blur'}
        ],
        platformMchId: [
          {required: true, message: '请输入服务商户号', trigger: 'blur'}
        ],
        appId: [
          {required: true, message: '请输入appId', trigger: 'blur'}
        ],
        mchId: [
          {required: true, message: '请输入商户号', trigger: 'blur'}
        ],
        mchKey: [
          {required: true, message: '请输入商户Key', trigger: 'blur'}
        ],
        keyPath: [
          {required: true, message: '请输入证书路径', trigger: 'blur'}
        ],
        notifyUrl: [
          {required: true, message: '请输入通知Url', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    async add() {
      try {
        let valid = await this.$refs["ruleForm"].validate();
        if (!valid) {
          return;
        }
      } catch (e) {
        return;
      }

      await this.addData();
    },
    async addData() {
      let data = this.form;
      const loading = ElLoading.service({
        lock: true,
        text: '数据处理中',
        background: 'rgba(0, 0, 0, 0.7)',
      })

      let res = await this.$http.form("/payConfig/create", data);

      loading.close();

      if (res.code !== 200) {
        this.$message.error(res.msg);
        return;
      }

      this.$message({
        message: '添加数据成功',
        type: 'success'
      });
      this.$router.go(-1);
    },

  },
  mounted() {
  }
}

</script>

<style scoped>
</style>
